package com.WicsApp.android;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.content.pm.ActivityInfo;

public class MainMenuActivity extends BaseActivity 
{
    /** Called when the activity is first created. */
    @Override
    public void setContentView(View view) 
    {
     super.setContentView(view);
    }
    
    
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mainmenu);
        //set to portrait mode
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        
        
        
        ListView menuList = (ListView) findViewById(R.id.listView1);
        String [] items = { getResources().getString(R.string.minutes),
        					getResources().getString(R.string.events),
        					getResources().getString(R.string.website),
        					getResources().getString(R.string.about)};
        
        // This is to populate the ListView control.
        ArrayAdapter<String> adapt = new ArrayAdapter<String>(this,R.layout.menu_item, items);
        
        menuList.setAdapter(adapt);
        
        //set up listeners for the listView events
        menuList.setOnItemClickListener(new AdapterView.OnItemClickListener()
        {
        	public void onItemClick(AdapterView<?> parent, View itemClick, int position, long id)
        	{
        		TextView textView = (TextView) itemClick;
        		String strText = textView.getText().toString();
        		if(strText.equalsIgnoreCase(getResources().getString(R.string.minutes)))
        		{
        			//launch the minutes activity
        			startActivity(new Intent(MainMenuActivity.this,MinutesActivity.class));
        		}
        		else if(strText.equalsIgnoreCase(getResources().getString(R.string.events)))
        		{
        			//launch the events activity
        			startActivity(new Intent(MainMenuActivity.this,EventsActivity.class));
        		}
        		else if(strText.equalsIgnoreCase(getResources().getString(R.string.about)))
        		{
        			//launch the about activity
        			startActivity(new Intent(MainMenuActivity.this,AboutActivity.class));
        		}
        		else if(strText.equalsIgnoreCase(getResources().getString(R.string.website)))
        		{
        			//open browser
        			Uri uri =Uri.parse("http://cgi.sfu.ca/~wics/");
        	        Intent intent = new Intent(Intent.ACTION_VIEW,uri);
        	        startActivity(intent);
        		}
        	}
        
        });
        
    }
    
    
}